package com.zl.roomdesign.main

import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.ViewGroup
import com.zl.core.WebActivity
import com.zl.core.base.BaseActivity
import com.zl.core.extend.inflate
import com.zl.roomdesign.R
import kotlinx.android.synthetic.main.activity_recommend.*
import kotlinx.android.synthetic.main.item_recommend.view.*

/**
 * Created by zhangli on 2018/5/7,23:36<br/>
 */
class RecommendActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_recommend)

        val list = listOf(RecommendEntity(R.drawable.safa, "沙发", "https://h5.m.taobao.com/awp/core/detail.htm?id=567790585732&ali_refid=a3_430680_1006:1110752039:N:%E6%B2%99%E5%8F%91:44e9f07b92f1121a5e07c7a4ab335e6b&ali_trackid=1_44e9f07b92f1121a5e07c7a4ab335e6b&spm=0.0.0.0"),
                    RecommendEntity(R.drawable.bed, "床", "https://detail.tmall.com/item.htm?spm=a230r.1.14.6.611871e3Y9nyVG&id=21777308052&cm_id=140105335569ed55e27b&abbucket=18&sku_properties=122216927:77835123"),
                    RecommendEntity(R.drawable.chaji, "茶几", "https://detail.tmall.com/item.htm?id=559242539843&ali_refid=a3_430583_1006:1104965215:N:%E5%AE%B6%E5%85%B7%E8%8C%B6%E5%87%A0:029bbdfa28db674b92b36e9955219318&ali_trackid=1_029bbdfa28db674b92b36e9955219318&spm=a230r.1.14.1&sku_properties=29112:97926"),
                    RecommendEntity(R.drawable.yigui, "衣柜", "https://detail.tmall.com/item.htm?id=564475021910&ali_refid=a3_430583_1006:1151836785:N:%E5%AE%B6%E5%85%B7%20%E8%A1%A3%E6%9F%9C:3e45da380d93723778e912b78bb88fcb&ali_trackid=1_3e45da380d93723778e912b78bb88fcb&spm=a230r.1.14.1&skuId=3732469458841"),
                    RecommendEntity(R.drawable.dianshi, "电视柜", "https://detail.tmall.com/item.htm?id=529463025179&ali_refid=a3_430583_1006:1104965215:N:%E5%AE%B6%E5%85%B7%20%E7%94%B5%E8%A7%86%E6%9F%9C:e922da8b8f3e537eb8ce0c37d38f17c9&ali_trackid=1_e922da8b8f3e537eb8ce0c37d38f17c9&spm=a230r.1.14.1&sku_properties=29112:16541580"),
                    RecommendEntity(R.drawable.canzhuo, "餐桌", "https://detail.tmall.com/item.htm?id=531730116713&ali_refid=a3_430583_1006:1102225352:N:%E5%AE%B6%E5%85%B7%E9%A4%90%E6%A1%8C:1894360d00b9eabc0cb5fdd63b985596&ali_trackid=1_1894360d00b9eabc0cb5fdd63b985596&spm=a230r.1.14.1"),
                    RecommendEntity(R.drawable.shuzhuo, "书桌", "https://detail.tmall.com/item.htm?spm=a230r.1.14.6.459f3769qdctl0&id=559437801436&cm_id=140105335569ed55e27b&abbucket=18&sku_properties=10187648:21959")
                )

        recyclerView.layoutManager = LinearLayoutManager(this)
        recyclerView.adapter = object : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

            override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
                val view = parent.inflate(R.layout.item_recommend, parent, false)
                return object : RecyclerView.ViewHolder(view) {}
            }

            override fun getItemCount() = list.size

            override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {

                holder.itemView.img.setImageResource(list[position].id)

                holder.itemView.txt.text = list[position].name

                holder.itemView.setOnClickListener {
                    val intent = Intent(this@RecommendActivity, WebActivity::class.java)
                    intent.putExtra(WebActivity.URL, list[position].url)
                    startActivity(intent)
                }
            }
        }

    }
}